Skip to content

gh-123726: Document caveats of zipfile.Path around name sanitization - #130537

Merged
jaraco merged 4 commits into
python:mainfrom
AffanShaikhsurab:main
Mar 8, 2025
Merged

jaraco merged 4 commits into
python:mainfrom
AffanShaikhsurab:main

Conversation

@AffanShaikhsurab

@AffanShaikhsurab AffanShaikhsurab commented Feb 25, 2025 •

Copy link
Copy Markdown
Contributor

Add a note to the zipfile.Path class documentation clarifying that it does not sanitize filenames. This emphasizes the caller's responsibility to validate or sanitize inputs, especially when handling untrusted ZIP archives, to prevent path traversal vulnerabilities. The note also references the extract and extractall methods for comparison and suggests using os.path.abspath and os.path.commonpath for safe filename resolution.

This Pr solves the issue #123726


📚 Documentation preview 📚: https://cpython-previews--130537.org.readthedocs.build/

…ation



Add a note to the `zipfile.Path` class documentation clarifying that it does not sanitize filenames. This emphasizes the caller's responsibility to validate or sanitize inputs, especially when handling untrusted ZIP archives, to prevent path traversal vulnerabilities. The note also references the `extract` and `extractall` methods for comparison and suggests using `os.path.abspath` and `os.path.commonpath` for safe filename resolution.
@ghost

ghost commented Feb 25, 2025 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@jaraco jaraco self-assigned this Mar 8, 2025
@jaraco jaraco added needs backport to 3.12 only security fixes needs backport to 3.13 only security fixes labels Mar 8, 2025
@jaraco
jaraco merged commit a3990df into python:main Mar 8, 2025
@github-project-automation github-project-automation Bot moved this from Todo to Done in Docs PRs Mar 8, 2025
@miss-islington-app

Copy link
Copy Markdown

Thanks @AffanShaikhsurab for the PR, and @jaraco for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 8, 2025
…ation (pythonGH-130537)

Add a note to the `zipfile.Path` class documentation clarifying that it does not sanitize filenames. This emphasizes the caller's responsibility to validate or sanitize inputs, especially when handling untrusted ZIP archives, to prevent path traversal vulnerabilities. The note also references the `extract` and `extractall` methods for comparison and suggests using `os.path.abspath` and `os.path.commonpath` for safe filename resolution.
(cherry picked from commit a3990df)

Co-authored-by: Affan Shaikhsurab <51104750+AffanShaikhsurab@users.noreply.github.com>
@bedevere-app

bedevere-app Bot commented Mar 8, 2025

Copy link
Copy Markdown

GH-130986 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label Mar 8, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 8, 2025
…ation (pythonGH-130537)

Add a note to the `zipfile.Path` class documentation clarifying that it does not sanitize filenames. This emphasizes the caller's responsibility to validate or sanitize inputs, especially when handling untrusted ZIP archives, to prevent path traversal vulnerabilities. The note also references the `extract` and `extractall` methods for comparison and suggests using `os.path.abspath` and `os.path.commonpath` for safe filename resolution.
(cherry picked from commit a3990df)

Co-authored-by: Affan Shaikhsurab <51104750+AffanShaikhsurab@users.noreply.github.com>
@bedevere-app

bedevere-app Bot commented Mar 8, 2025

Copy link
Copy Markdown

GH-130987 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.12 only security fixes label Mar 8, 2025

@jaraco jaraco left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read this over a few times. I considered changing it to point out that it's mostly relevant when manifesting names in a file system, or making a reference to the open issues around providing a sanitizing extractor, but decided against that. This is a good, complete contribution. Thanks!

jaraco pushed a commit that referenced this pull request Mar 8, 2025
…zation (GH-130537) (#130986)

gh-123726: Document caveats of zipfile.Path around name sanitization (GH-130537)

Add a note to the `zipfile.Path` class documentation clarifying that it does not sanitize filenames. This emphasizes the caller's responsibility to validate or sanitize inputs, especially when handling untrusted ZIP archives, to prevent path traversal vulnerabilities. The note also references the `extract` and `extractall` methods for comparison and suggests using `os.path.abspath` and `os.path.commonpath` for safe filename resolution.
(cherry picked from commit a3990df)

Co-authored-by: Affan Shaikhsurab <51104750+AffanShaikhsurab@users.noreply.github.com>
jaraco pushed a commit that referenced this pull request Mar 8, 2025
…zation (GH-130537) (#130987)

gh-123726: Document caveats of zipfile.Path around name sanitization (GH-130537)

Add a note to the `zipfile.Path` class documentation clarifying that it does not sanitize filenames. This emphasizes the caller's responsibility to validate or sanitize inputs, especially when handling untrusted ZIP archives, to prevent path traversal vulnerabilities. The note also references the `extract` and `extractall` methods for comparison and suggests using `os.path.abspath` and `os.path.commonpath` for safe filename resolution.
(cherry picked from commit a3990df)

Co-authored-by: Affan Shaikhsurab <51104750+AffanShaikhsurab@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants